@model RegisterViewModel
@{
    ViewData["Title"] = "注册";
}
@section PYhead{
    <link href="~/css/Account.css" type="text/css" rel="stylesheet">
    <link href="~/css/lar.css" type="text/css" rel="stylesheet">
    <script src="~/js/Account.js"></script>
    <style>
        .validation-summary-errors ul {
            color: red;
            font-size: 15px;
            margin-left: 0;
            padding: 0;
            list-style-type: none;
        }

        .validation-summary-errors ul li {
            color: red;
            font-size: 15px;
            margin-left: 20px;
        }
    </style>
}
<div class="topbar">
    <ul class="itm">
        <li class="acitm" style="float: left;"><a asp-action="Index" asp-controller="Home">返回主页</a></li>
        <li class="acitm" style="float: right;">用户系统</li>
    </ul>
</div>
<div class="lgboard">
    <form asp-for="Register" asp-controller="Account" method="post">
        <p class="lgtitle">注册</p>
        <p class="warn-p" id="name-warn">用户名已被注册</p>
        <p class="warn-p" id="email-warn">邮箱格式错误</p>
        <p class="warn-p" id="passwd-warn">密码需要由数字，一个大写字母，一个小写字母，一个符号组成</p>
        <p class="warn-p" id="passwdc-warn">前后密码不一致</p>
        <div asp-validation-summary="All"></div>
        <input type="text" asp-for="UserName" oninput="CheckUserName()" class="inputer" name="UserName" id="formname" placeholder="请输入用户名">
        <input type="text" asp-for="Email" class="inputer" name="Email" oninput="CheckEmail()" placeholder="请输入邮箱">
        <input type="password" asp-for="Password" class="inputer" oninput="CheckPassword()" name="password" id="password" placeholder="请输入密码">
        <input type="password" asp-for="ConfirmPassword" class="inputer" oninput="checkpsw()" name="ConfirmPassword" placeholder="请再次输入密码">
        <input type="text" asp-for="InvCode" class="inputer" name="InvCode" placeholder="请输入材社后的四个社名">
        <input type="text" asp-for="InvCodea" class="inputer" name="InvCodea" placeholder="请输入培英中学2017年校长名字">
        <a asp-action="Login" asp-controller="Account"><p class="jumper">已有账号</p></a>
        <input type="submit" class="subm" id="submiter" value="注册">
    </form>
</div>
<script src="~/js/jquery-3.6.0.min.js"></script>
<script>
    $('#submiter').attr("disabled", "true");
    function CheckUserName() {
        var s=$("#formname").val();
        if (s == null)
            return;
        $.ajax({
            url: "/Account/CheckUserName",
            async: true,
            data: {
                UserName: $("#formname").val()
            },
            type: "post",
            dataType: "text",
            success: function (response) {
                response = JSON.parse(response);
                if (response == "OK") {
                    $("#formname").css("box-shadow", " 0px 0px 1px 1px green");
                    $('#name-warn').css("display", "none");
                    $('#submiter').removeAttr("disabled");
                }
                else {
                    $("#formname").css("box-shadow", " 0px 0px 1px 1px red");
                    $('#name-warn').css("display", "block");
                    $('#submiter').attr("disabled", "true");
                }
            }
        });
    }

    function CheckPassword() {
        var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
        var s = $("#password").val();
        if (strongRegex.test($('#password').val())) {
            $('#submiter').removeAttr("disabled");
            $('#passwd-warn').css("display", "none");
        } else {
            $('#passwd-warn').css("display", "block");
            $('#submiter').attr("disabled", "true");
        }
    }
</script>
